package com.example.sdkumeng.share;

import android.app.Activity;
import android.content.Context;

import com.forxindu.kit.box.JavaKit;
import com.umeng.socialize.Config;
import com.umeng.socialize.ShareAction;
import com.umeng.socialize.UMShareListener;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.media.UMImage;

public class ShareHelper {

    private Context context;
    private BHaiGouShareContent shareContent;
    private UMShareListener umShareListener;

    public ShareHelper(Context mContext) {
        this.context = mContext;
        this.init();
    }

    private void init() {
        //微信
//        PlatformConfig.setWeixin(AndroidKit.getMetaDataValue(context, Platform.WECHAT_SOCIAL_APP_ID), AndroidKit.getMetaDataValue(context, Platform.WECHAT_SOCIAL_APP_SECRET));
        //新浪微博
//        PlatformConfig.setSinaWeibo(AndroidKit.getMetaDataValue(context, Platform.WEIBO_SOCIAL_APP_ID), AndroidKit.getMetaDataValue(context, Platform.WEIBO_SOCIAL_APP_SECRET));
        Config.DEBUG = true;
        //QQ
//        PlatformConfig.setQQZone(AndroidKit.getMetaDataValue(context,Platform.QQ_SOCIAL_APP_ID),AndroidKit.getMetaDataValue(context,Platform.QQ_SOCIAL_APP_KEY));
    }

    public void sinaShare() {
        if (shareContent != null) {
            ShareAction shareAction = new ShareAction((Activity) context);
            shareAction.withText(shareContent.getContent());
            if (shareContent.getImage() != null) {
                shareAction.withMedia(new UMImage(context, shareContent.getImage()));
            }
            if (!JavaKit.isStringEmpty(shareContent.getImageUrl())) {
                shareAction.withMedia(new UMImage(context, shareContent.getImageUrl()));
            }
            shareAction.withTitle(shareContent.getTitle());
            shareAction.withTargetUrl(shareContent.getContentUrl());
            shareAction.setPlatform(SHARE_MEDIA.SINA);
            shareAction.setCallback(getUmShareListener());
            shareAction.share();
            shareContent = null;
        }
    }

    public void weixin() {
        if (shareContent != null) {
            ShareAction shareAction = new ShareAction((Activity) context);
            shareAction.withText(shareContent.getContent());
            if (shareContent.getImage() != null) {
                shareAction.withMedia(new UMImage(context, shareContent.getImage()));
            }
            if (!JavaKit.isStringEmpty(shareContent.getImageUrl())) {
                shareAction.withMedia(new UMImage(context, shareContent.getImageUrl()));
            }
            shareAction.withTitle(shareContent.getTitle());
            shareAction.withTargetUrl(shareContent.getContentUrl());
            shareAction.setPlatform(SHARE_MEDIA.WEIXIN);
            shareAction.setCallback(getUmShareListener());
            shareAction.share();
            shareContent = null;
        }
    }

    public void weixinFriends() {
        if (shareContent != null) {
            ShareAction shareAction = new ShareAction((Activity) context);
            shareAction.withText(shareContent.getContent());
            if (shareContent.getImage() != null) {
                shareAction.withMedia(new UMImage(context, shareContent.getImage()));
            }
            if (!JavaKit.isStringEmpty(shareContent.getImageUrl())) {
                shareAction.withMedia(new UMImage(context, shareContent.getImageUrl()));
            }
            shareAction.withTitle(shareContent.getTitle());
            shareAction.withTargetUrl(shareContent.getContentUrl());
            shareAction.setPlatform(SHARE_MEDIA.WEIXIN_CIRCLE);
            shareAction.setCallback(getUmShareListener());
            shareAction.share();
            shareContent = null;
        }
    }

    public void qqZoneShare() {
        if (shareContent != null) {
            ShareAction shareAction = new ShareAction((Activity) context);
            shareAction.withText(shareContent.getContent());
            if (shareContent.getImage() != null) {
                shareAction.withMedia(new UMImage(context, shareContent.getImage()));
            }
            if (!JavaKit.isStringEmpty(shareContent.getImageUrl())) {
                shareAction.withMedia(new UMImage(context, shareContent.getImageUrl()));
            }
            shareAction.withTitle(shareContent.getTitle());
            shareAction.withTargetUrl(shareContent.getContentUrl());
            shareAction.setPlatform(SHARE_MEDIA.QZONE);
            shareAction.setCallback(getUmShareListener());
            shareAction.share();
            shareContent = null;
        }
    }

    public void qqShare() {
        if (shareContent != null) {
            ShareAction shareAction = new ShareAction((Activity) context);
            shareAction.withText(shareContent.getContent());
            if (shareContent.getImage() != null) {
                shareAction.withMedia(new UMImage(context, shareContent.getImage()));
            }
            if (!JavaKit.isStringEmpty(shareContent.getImageUrl())) {
                shareAction.withMedia(new UMImage(context, shareContent.getImageUrl()));
            }
            shareAction.withTitle(shareContent.getTitle());
            shareAction.withTargetUrl(shareContent.getContentUrl());
            shareAction.setPlatform(SHARE_MEDIA.QQ);
            shareAction.setCallback(getUmShareListener());
            shareAction.share();
            shareContent = null;
        }
    }

    public void alipayShare() {
        if (shareContent != null) {
            ShareAction shareAction = new ShareAction((Activity) context);
            shareAction.withText(shareContent.getContent());
            if (shareContent.getImage() != null) {
                shareAction.withMedia(new UMImage(context, shareContent.getImage()));
            }
            if (!JavaKit.isStringEmpty(shareContent.getImageUrl())) {
                shareAction.withMedia(new UMImage(context, shareContent.getImageUrl()));
            }
            shareAction.withTitle(shareContent.getTitle());
            shareAction.withTargetUrl(shareContent.getContentUrl());
            shareAction.setPlatform(SHARE_MEDIA.ALIPAY);
            shareAction.setCallback(getUmShareListener());
            shareAction.share();
            shareContent = null;
        }
    }

    public UMShareListener getUmShareListener() {
        return umShareListener;
    }

    public void setUmShareListener(UMShareListener umShareListener) {
        this.umShareListener = umShareListener;
    }

    /**
     * @return the shareContent
     */
    public BHaiGouShareContent getShareContent() {
        return shareContent;
    }

    /**
     * @param shareContent the shareContent to set
     */
    public void setShareContent(BHaiGouShareContent shareContent) {
        this.shareContent = shareContent;
    }
}
